package com.shambles.manage2.tkmapper.mapper;

import com.shambles.manage2.tkmapper.entity.SysUser;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface SysUserMapper extends Mapper<SysUser>, InsertListMapper<SysUser> {

    @Select("SELECT url FROM(SELECT model_guid FROM (SELECT role_guid FROM sys_user_role WHERE user_guid = '${userGuid}') role " +
            "LEFT JOIN sys_role_model srm ON role.role_guid = srm.role_guid) " +
            "model LEFT JOIN sys_model_url smu ON model.model_guid=smu.model_guid")
    List<String> userAllPermission(@Param("userGuid") String userGuid);

    /**
     * 查询用户列表接口
     */
    @Select("select * from sys_user where post='${post}'")
    List<SysUser> querUserAll(@Param("post") String post);

    /**
     * 删除商户
     */
    @Delete("delete from sys_user where guid='${guid}'")
    void deleteSysUser(@Param("guid") String guid);

    /**
     * 修改商户
     */
    void updateSysUser(SysUser sysUser );

    /**
     * 添加商户
     */
    SysUser insertSysUser(SysUser sysUser);

    /**
     * 合格的管理员 （必须关注过公众号并且注册）
     * @return
     */
    @Select("SELECT open_id FROM cost c LEFT JOIN usersinfo u on c.merchant_name = u.`name`")
    List<String> findCheckOK();
}